
var map;
var layera, layerb, layerkec, layerkab, layerdes, layerb_inited=0;
var klik;
var id_map_kecamatan='1-ar6StjujQkE4vG-2KGDO0gomCMUz3IP5v14Nvk',
id_map_desa='1wsg6GLA4PUIAF16wVN7ssGT5bm4lIVVl_wA_TWo',
id_map_kabupaten='1wsg6GLA4PUIAF16wVN7ssGT5bm4lIVVl_wA_TWo';

function initialize() {
    klik =0;
    var kukar = new google.maps.LatLng(-0.2048488428669741,116.88081478124991);

    map = new google.maps.Map(document.getElementById('map_canvas'), {
        center: kukar,
        zoom: 8,
        mapTypeControl: false,
        panControl: false,
        mapTypeControlOptions: {
            style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
        },
        zoomControl: true,
        zoomControlOptions: {
            style: google.maps.ZoomControlStyle.SMALL,
            position: google.maps.ControlPosition.RIGHT_TOP
        },
        mapTypeId: google.maps.MapTypeId.TERRAIN
    });
        
        
        
        
    //    layerkab = new google.maps.FusionTablesLayer({
    //        query: {
    //            select: '\'geometry\'',
    //            from: '1-ar6StjujQkE4vG-2KGDO0gomCMUz3IP5v14Nvk'
    //        }
    //    });
    //layerkab.setMap(map);
    
    
//    centangKabupaten();
//    centangKecamatan();
//    centangdesa();
//    $('#administrasi_cek').attr('checked',true);

}
      
function test(kecamatan){
    if (klik==0){
        layera = new google.maps.FusionTablesLayer({
            query: {
                select: '\'geometry\'',
                from: id_map_kecamatan,
                where : 'KECAMATAN = \''+kecamatan+'\''
            }
            ,
            styles: [{
                polygonOptions: {
                    fillColor: "#ff5400",
                    fillOpacity:1.0
                }
            }]
        });
        layera.setMap(map); 
    }
}
      
function test1(){
    if(klik==0){
        layera.setMap(null); 
    }
    else if (klik==1){
             
    }
}
      
function testklik(kecamatan){
    layera.setMap(null);
    if(layerb_inited==1)
        layerb.setMap(null);
    layerb_inited=1;
    layerb = new google.maps.FusionTablesLayer({
        query: {
            select: '\'geometry\'',
            from: '1wsg6GLA4PUIAF16wVN7ssGT5bm4lIVVl_wA_TWo',
            where : 'KECAMATAN = \''+kecamatan+'\''
        },
        styles: [{
            polygonOptions: {
                fillColor: "#ffaaaa",
                fillOpacity:1.0
            }
        }]
    });
    layerb.setMap(map);
}
      
$(document).ready(function(){
    $("#rc1").change(function(){
        if($(this).is(':checked')) {   
            $('#c1').attr('checked', 'checked');
            $('#c2').attr('checked', 'checked'); 
            $('#c3').attr('checked', 'checked'); 
        }
    })
          
          
          
    $("#desa_cek").change(function(){
        if($(this).is(':checked')) {   
            centangdesa();
        }
        else {
            uncentangdesa();
        }
    })
          
    $("#administrasi_cek").change(function(){
        if($(this).is(':checked')) {  
            centangdesa();
            centangKecamatan();
            centangKabupaten();
            $('#desa_cek').attr('checked', true);
            $('#kecamatan_cek').attr('checked', true); 
            $('#kabupaten_cek').attr('checked', true); 
        }
        else{
            
            $('#desa_cek').attr('checked', false);
            $('#kecamatan_cek').attr('checked', false); 
            $('#kabupaten_cek').attr('checked', false); 
            uncentangdesa();
            uncentangKecamatan();
            uncentangKabupaten();
        }
    })
          
          
          
          
    $("#kecamatan_cek").change(function(){
        
        if($(this).is(':checked')) {   
            centangKecamatan();
        }
        else {
            uncentangKecamatan();
        }
    })
          
          
          
});
        
function change_map_view(tipe)
{
    if(tipe==1)
        map.setMapTypeId(google.maps.MapTypeId.SATELLITE);
    else if(tipe==2)
        map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
    else if(tipe==3)
        map.setMapTypeId(google.maps.MapTypeId.HYBRID);
    else if(tipe==4)
        map.setMapTypeId(google.maps.MapTypeId.TERRAIN);
}
      
      
function centangdesa(){
    layerdes = new google.maps.FusionTablesLayer({
        query: {
            select: '\'geometry\'',
            from: id_map_desa
        }
    //        ,
    //        styles: [{
    // 
    //            polygonOptions: {
    //                //fillOpacity: 0.0
    //            }
    //        }]
    });
    layerdes.setMap(map);
    if($('#kecamatan_cek').is(':checked')) {   
        layerkec.setMap(null);
        layerkec.setMap(map);
    }
}
function uncentangdesa(){
    layerdes.setMap(null);
}

function centangKecamatan(){
    
    layerkec = new google.maps.FusionTablesLayer({
        query: {
            select: '\'geometry\'',
            from: id_map_kecamatan
        }
    });
    layerkec.setMap(map);
}
function uncentangKecamatan(){
    layerkec.setMap(null);
}
function centangKabupaten(){
//    layerkab = new google.maps.FusionTablesLayer({
//        query: {
//            select: '\'geometry\'',
//            from: '1wsg6GLA4PUIAF16wVN7ssGT5bm4lIVVl_wA_TWo'
//        }
//    });
//    layerkab.setMap(map);
}
function uncentangKabupaten(){
//layerkab.setMap(null);
}